/**
  * @file conectar.java
  * @brief Clase conectar
  * @author Jose Antonio Lozano
  * @date Marzo 2013
  */

package sgeb;

import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
/**
 *
 * @author lozano
 * @fecha 20/03/2013
 */

public class conectar {
Connection conect = null;

   /*Función para conectar con la Base de Datos*/
   public Connection conexion()
    {
      try {             
           //Cargamos el Driver MySQL
           Class.forName("org.gjt.mm.mysql.Driver");
           conect = DriverManager.getConnection("jdbc:mysql://db4free.net:3306/sgeb","sgeb","sgebis3");
	   //conect = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/sgeb","root","");
           JOptionPane.showMessageDialog(null,"conectado");
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null,"Error "+e);
        }
        return conect;
     
}
   /**
    * Nos permite conocer el valor de la última variable de autoincremento
    * @return valor de la última variable de autoincremento usada
    * @author Borja Molina Zea
    */
    public int getLastID(){
         int ultimoID = -1;   
         try{
            Statement stm = this.conect.createStatement();
            ResultSet rs = stm.executeQuery("select LAST_INSERT_ID()");
            while(rs.next()){
                ultimoID = rs.getInt("LAST_INSERT_ID()");
            }  
        } catch (SQLException ex) {
            Logger.getLogger(Entrenador.class.getName()).log(Level.SEVERE, null, ex);
        }
        return ultimoID;
     }
}
